﻿// -----------------------------------------------------------------------
// <copyright file="LinkDtoMapperExtension.cs">
// Copyright (c) 2014 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com  andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Mappers
{
	using Moveax.DataAccess.Cqrs.Highway.EF.UnitTests.DataAccess.Database.Dto;
	using Moveax.DataAccess.Cqrs.Highway.UnitTests.Model;

	internal static class LinkDtoMapperExtension
	{
		public static Link ToModel(this LinkDto source)
		{
			return source.ToModel(ignoreNavigation: false);
		}

		public static Link ToModel(this LinkDto source, bool ignoreNavigation)
		{
			if (source == null)
				return null;

			var link = new Link() {
				// In alphabetical order without navigation properties
				Id = source.Id,
				Title = source.Title,
				Url = source.Url,
				UserProfileId = source.UserProfileId
			};

			if (source.UserProfile != null && !ignoreNavigation)
				link.UserProfile = source.UserProfile.ToModel(ignoreNavigation: true);

			return link;
		}
	}
}